<?php
global $wpdb, $userdata, $current_user;
require_once('./wp-admin/includes/user.php');

$user_info = get_userdata($valgt_medlem);

$instrument = get_the_author_meta('instrument', $user_info->ID);
$resInstrument = $wpdb->get_row("SELECT feltdata FROM feltdata WHERE feltdataid ='$instrument'");

$postnr = get_the_author_meta('postnr', $user_info->ID);
$resPostnr = $wpdb->get_row("SELECT stedsnavn FROM poststed WHERE postnr ='$postnr'");
?>

<div id="container">
    
    <h2>Profil for <?php echo "$user_info->first_name $user_info->last_name" ?></h2>
    <div class="profilBilde">
    <?php echo get_avatar($auser['email'], $size = '125', $default = 'http://i45.tinypic.com/oky8na.jpg'); ?>
    </div>
    <form class="adminButtons" method="post" action="<?php the_permalink() ?>">
        <input name="action" type="submit" value="Tilbake"/>
    <?php if (current_user_can('edit_user') || $valgt_medlem == $current_user->id) { ?>
        <input name="action" type="submit" value="Endre profil"/>
    <?php }
    if (current_user_can('delete_user')) { ?>
        <input name="action" type="submit" value="Slett"/>
    <?php } ?>
        <input name="idnum" type="hidden" value="<?php echo $valgt_medlem ?>"/>
    </form>
    <form class="adminButtons" method="post" action="/?page_id=1080">
        <input name="action" type="submit" value="Send epost"/>
        <input name="idnum" type="hidden" value="<?php echo $valgt_medlem ?>"/>
        <input name="framodul" type="hidden" value="<?php the_permalink() ?>"/>
        <input name="til-side" type="hidden" value="profil"/>
    </form>
    <div id="content" role="main">

        <table width="50%" cellspacing="0" cellpadding="0" border="0">
            <tr>
                <td>Navn: </td>
                <td><?php echo "$user_info->first_name $user_info->last_name" ?></td>
            </tr>
            <tr>
                <td>Epost: </td>
                <td><?php echo $user_info->user_email ?></td>
            </tr>
            <tr>
                <td>Instrument: </td>
                <td><?php echo esc_attr($resInstrument->feltdata); ?></td>
            </tr>
            <tr>
                <td>Fødselsdag: </td>
                <?php $fd = get_the_author_meta('fødselsdag', $user_info->ID);
                $år = intval(substr($fd, 0, 4));
                $md = zeroise(intval(substr($fd, 5, 2)), 2);
                $dg = zeroise(intval(substr($fd, 8, 2)), 2); ?>
                <td><?php echo esc_attr("$dg.$md.$år") ?></td>
            </tr>
            <tr>
                <td>Adresse: </td>
                <td><?php echo esc_attr(get_the_author_meta('adresse', $user_info->ID)); ?></br><?php echo esc_attr(get_the_author_meta('postnr', $user_info->ID)) . " " . esc_attr($resPostnr->stedsnavn); ?></td>
            </tr>
            <tr>
                <td>Telefon: </td>
                <td><?php echo esc_attr(get_the_author_meta('telefon', $user_info->ID)); ?></td>
            </tr>
            <tr>
                <td>Beskrivelse: </td>
                <td style="width:90%"><?php echo esc_attr(get_the_author_meta('description', $user_info->ID)); ?></td>
            </tr>
        </table>
    </div><!-- #content -->

</div><!-- #container -->
